<?php

namespace haibao\user\data\payment;

class VipProduct extends \haibao\user\data\BaseMysql {
    
	public function __construct(){
		$this->setConfig( \haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER );
	}
	
	/**
	 * 根据产品id查询vip产品信息
	 */
	public function getProductByProductId($productId){
	    $cache = new \haibao\user\cache\Payment();
	    $product = $cache->getProductByPrdocutId($productId);
	    if(!$product){
	        $result = $this->query('select * from VipProduct where ProductId=%s and Status=%s limit 1', array(
	            $productId, \haibao\user\model\data\payment\VipProduct::STATUS_ENABLE
	        ));
	        $product = $result->fetch_assoc();
	        $cache->setProductByProduct($product['ProductId'], $product);
	    }
	    return $product;
	}
	
	/**
	 * 取当前可用套餐信息
	 */
	public function getVipProduct(){
	    $cache = new \haibao\user\cache\Payment();
	    $product = $cache->getVipProducts();
	    if(!$product){
	        $result = $this->query('select * from VipProduct where Status=%s order by ProductPrice asc', array(
	            \haibao\user\model\data\payment\VipProduct::STATUS_ENABLE
	        ));
	        $product = array();
	        while ($row = $result->fetch_assoc()){
	            array_push($product, $row);
	        }
	        $cache->setVipProducts($product);
	    }
	    return $product;
	}

}
